package com.cn.wanxi.util.utils;

import com.cn.wanxi.util.model.AboutContentModel;
import com.cn.wanxi.util.model.AboutNavModel;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class FileUtile {
    public String readFileToString(String filename){
    StringBuffer stringBuffer = new StringBuffer();
    BufferedReader br = null;
        try {
            /**
             * this.getClass() 获取当前类对象
             * getClassLoader() 获取类加载器
             * getResourceAsStream（"文件名"） 获取resources文件夹下的文件，并转为字节流
             * */
            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(filename);
            //将字节流转为字符流
            br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
            //通过字符流读取
            String line = null;

            while ((line = br.readLine()) != null) {
                stringBuffer.append(line);
            }
            System.out.println(stringBuffer);

//            关闭字符流
            br.close();

            return stringBuffer.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}